/*
As3 Performances Analyzer
Copyright (C) 2011 Ankama Studio

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

Contact : seyraud@ankama.com
Project : http://code.google.com/p/as3-performances-analyzer
*/

package types
{
	import interfaces.IFrameActionContainer;
	import interfaces.ITimelineData;

	public class Frame implements IFrameActionContainer, ITimelineData
	{
		//:///////////////////////////////////////////////////////////////////
		//:// Privates variables
		//:///////////////////////////////////////////////////////////////////
		
		private var _id : uint;
		private var _start : uint;
		private var _end : uint;
		private var _children : Vector.<ITimelineData> = new Vector.<ITimelineData>;
		private var _actionCount : uint;
		private var _duration : uint;
		private var _fps : Number;
		private var _customInfo : String;
		private var _legend : String;
		
		//:///////////////////////////////////////////////////////////////////
		//:// Getter / Setter
		//:///////////////////////////////////////////////////////////////////
		
		/** @inherited  */
		public function get name() : String {return "frame";}
		
		/** @inherited  */
		public function get id():uint{return _id;}/** @private */
		public function set id(value:uint):void{
			_id = value;
			_legend = "#" + _id +", " + actionCount + " action(s)";
		}

		/** @inherited */
		public function get start():uint{return _start;}/** @private */
		public function set start(value:uint):void{
			_start = value;
			_duration = _end - _start;
			_fps = 1000 / (_duration ? _duration : 1);
			_fps = _fps > 50 ? 50 : _fps;
		}

		/** @inherited */
		public function get end():uint{return _end;}/** @private */
		public function set end(value:uint):void{
			_end = value;
			_duration = _end - _start;
			_fps = 1000 / (_duration ? _duration : 1);
			_fps = _fps > 50 ? 50 : _fps;
		}
		
		/** @inherited */
		public function get duration():uint{return _duration;}
		
		/** @inherited */
		public function get depth():uint{return 0;}/** @private */
		public function set depth(value:uint):void{}
		
		/** @inherited  */
		public function get customInfo() : String {return _customInfo;}/** @private */
		public function set customInfo(value:String):void{_customInfo = value;}
		
		/** Frame root actions */
		public function get children():Vector.<ITimelineData>{return _children;} /** @private */
		public function set children(value:Vector.<ITimelineData>):void {_children = value;}
		
		/** Total action count including all sub frame actions */
		public function get actionCount():uint{return _actionCount;}/** @private */
		public function set actionCount(value:uint):void{
			_actionCount = value;
			_legend = "Frame\n#" + _id +", " + actionCount + " action(s)";
		}
		
		/** Frame fps */
		public function get fps() : Number
		{
			return _fps;
		}
		
		public function get legend() : String
		{
			return _legend;
		}
		
		//:///////////////////////////////////////////////////////////////////
		//:// Public function
		//:///////////////////////////////////////////////////////////////////
		
		public function toString() : String
		{
			var r : String = "Frame " + id + " took " + (end - start) + " ms, " + _children.length + " action(s)";
			var i : uint = 0;
			while(i < _children.length)
			{
				r += "\n" + _children[i];
				++i;
			}
			return r;
		}
	}
}